<?php

namespace app\admin\controller;

use buildView\Echarts;
use think\Controller;

/**
 * 门店概况
 * Class StoreForm
 * @package app\admin\controllerd
 */
class StoreForm extends Controller
{
    /**
     * 门店概况
     * @auth true
     * @menu true
     * @return mixed
     */
    public function index()
    {
        $store = session('store');
        if ($store){
            $store_id = $store['id'];
        }else{
            $store_id = $this->request->param('store_id');
        }
        $echart = new Echarts();
        $echart->create('shop_order', '账单统计', '', 'line')
            ->setHeader('营业额', 'sum', 'total_price', function ($q)use($store_id) {
            $q->where('status', 'neq',-1)->where('store_id',$store_id);;
        })->sum('预约消费', 'total_price', function ($q)use($store_id) {
            $q->where('type', 1)->where('store_id',$store_id)->where('status', 'neq',-1);
        })->sum('会员卡购买', 'total_price', function ($q)use($store_id) {
            $q->where('type', 5)->where('store_id',$store_id);
        })->sum('会员充值', 'total_price', function ($q)use($store_id) {
            $q->where('type', 6)->where('store_id',$store_id);
        });
        $echart->create('user', '会员统计', '', 'line', 'create_at')
            ->setHeader('会员', 'count', '*')
            ->count('会员',function ($q)use($store_id){
            $q->where('store_id',$store_id);
        });
        return $echart->view();
    }
}